using Cysharp.Threading.Tasks;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class MainCityEffectCtrl : TEntityGroupCtrl
    {
        public Transform effectRoot { get; private set; }

        public override EntityPoolGroupType groupType => EntityPoolGroupType.MainCityEntityEffect;

        protected override void OnSceneLoaded()
        {
            base.OnSceneLoaded();
            effectRoot = new GameObject("EffectRoot").transform;
            effectRoot.position = Vector3.zero;
        }

        public async UniTask<MainCityEntityEffectView> ShowEffectOnPoint(MainCityRealityEntity entity, EntityBindPointCommonType bindPointId, string effectName, Vector3 offset = default)
        {
            var bindPointCom = entity.AddComponentWithPool<EntityBindPointComponent>(ETComponentType.EntityBindPoint);
            if (bindPointCom == null)
            {
                LogGame.LogError("entity上找不到EntityBindPointComponent。");
                return null;
            }
            var bindPointTransform = bindPointCom.GetBindPoint(bindPointId);
            var effectEntity = await ShowEntity(bindPointTransform, PathConstant.GetEffectPrefabPath(effectName), offset);
            return effectEntity as MainCityEntityEffectView;
        }

        public async UniTask<MainCityEntityEffectView> ShowEffectOnPoint(MainCityRealityEntity entity, EntityBindPointCommonType bindPointId, int resCid, Vector3 offset = default)
        {
            return await ShowEntity(entity, bindPointId, resCid, offset) as MainCityEntityEffectView;
        }

        public UniTask<Entity> ShowEffect(Transform bindPointTrans, int resCid, Vector3 offset)
        {
            return ShowEntity(bindPointTrans, resCid, offset);
        }

        public UniTask<Entity> ShowEffect(Transform bindPointTrans, string effectPath, Vector3 offset)
        {
            return ShowEntity(bindPointTrans, effectPath, offset);
        }

        public void HideEffect(Entity e)
        {
            HideEntity(e);
        }
    }
}